package org.rainbowinverted.charging.device.connect.bl.server.handler;

import com.dix.codec.bkv.BKV;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import org.rainbowinverted.charging.device.connect.bl.server.message.out.BlDeviceRebootOut;
import org.springframework.stereotype.Component;

/**
 * 设备重启处理器
 * @author huaiping
 */
@Component
@ChannelHandler.Sharable
public class BlDeviceRebootHandler extends BlAbstractHandler<Boolean, BlDeviceRebootOut>{
    @Override
    public void write(BlDeviceRebootOut message, BKV bkv) {
        bkv.add(0x1f, message.getRebootDelay());
        createFuture(getSerialNo(bkv));
    }

    @Override
    public void read(ChannelHandlerContext channelHandlerContext, BKV bkv) {
        byte ack = getAck(bkv);
        complete(getSerialNo(bkv), ack == 0x01);
    }
}
